package game.model.converter;

import com.google.common.collect.Lists;
import common.model.po.GClassification;
import common.model.po.GClassificationInputId;
import game.model.compare.GClassificationCompare;
import game.model.dto.ClassificationTreeDto;
import game.model.request.SaveClassificationRequest;
import game.model.vo.CascadeClassificationVo;
import game.model.vo.ClassificationTreeVo;

import java.util.List;

/**
 * @author 米泽鹏
 * @since 2022-2-28 上午 11:36
 */
public class GClassificationConverter {

	public static List<CascadeClassificationVo> poListToCascadeClassificationVoList(List<GClassification> poList) {
		List<CascadeClassificationVo> voList = Lists.newArrayList();
		for (GClassification po : poList) {
			CascadeClassificationVo vo = new CascadeClassificationVo();
			vo.setValue(po.getId());
			vo.setLabel(po.getName());
			voList.add(vo);
		}
		return voList;
	}

	public static List<ClassificationTreeVo> dtoListToClassificationTreeVoList(List<ClassificationTreeDto> dtoList) {
		List<ClassificationTreeVo> voList = Lists.newArrayList();
		for (ClassificationTreeDto dto : dtoList) {
			ClassificationTreeVo vo = treeDtoToTreeVo(dto);
			voList.add(vo);
		}
		return voList;
	}

	public static List<GClassificationCompare> saveRequestListToCompareList(List<SaveClassificationRequest.ClassificationInfo> infoList) {
		List<GClassificationCompare> compareList = Lists.newArrayList();
		for (SaveClassificationRequest.ClassificationInfo request : infoList) {
			GClassificationCompare compare = saveRequestToCompare(request);
			compareList.add(compare);
		}
		return compareList;
	}

	public static List<GClassificationCompare> poListToCompareList(List<GClassification> poList) {
		List<GClassificationCompare> compareList = Lists.newArrayList();
		for (GClassification po : poList) {
			GClassificationCompare compare = poToCompare(po);
			compareList.add(compare);
		}
		return compareList;
	}

	public static List<GClassification> compareListToPoList(List<GClassificationCompare> compareList) {
		List<GClassification> poList = Lists.newArrayList();
		for (GClassificationCompare compare : compareList) {
			GClassification po = compareToPo(compare);
			poList.add(po);
		}
		return poList;
	}

	public static List<GClassificationInputId> poListToInputIdPoList(List<GClassification> poList) {
		List<GClassificationInputId> inputIdPoList = Lists.newArrayList();
		for (GClassification po : poList) {
			GClassificationInputId inputIdPo = poToInputIdPo(po);
			inputIdPoList.add(inputIdPo);
		}
		return inputIdPoList;
	}

	public static ClassificationTreeVo treeDtoToTreeVo(ClassificationTreeDto classificationTreeDto) {
		if (classificationTreeDto == null) {
			return null;
		}
		ClassificationTreeVo classificationTreeVo = new ClassificationTreeVo();
		classificationTreeVo.setId(classificationTreeDto.getId());
		classificationTreeVo.setParentId(classificationTreeDto.getParentId());
		classificationTreeVo.setType(classificationTreeDto.getType());
		classificationTreeVo.setSort(classificationTreeDto.getSort());
		classificationTreeVo.setName(classificationTreeDto.getName());
		classificationTreeVo.setCount(classificationTreeDto.getCount());
		return classificationTreeVo;
	}

	public static GClassificationCompare saveRequestToCompare(SaveClassificationRequest.ClassificationInfo classificationInfo) {
		if (classificationInfo == null) {
			return null;
		}
		GClassificationCompare gClassificationCompare = new GClassificationCompare();
		gClassificationCompare.setParentId(classificationInfo.getParentId());
		gClassificationCompare.setType(classificationInfo.getType());
		gClassificationCompare.setSort(classificationInfo.getSort());
		gClassificationCompare.setName(classificationInfo.getName());
		gClassificationCompare.setTreeNodeId(classificationInfo.getTreeNodeId());
		gClassificationCompare.setParentTreeNodeId(classificationInfo.getParentTreeNodeId());
		gClassificationCompare.setId(classificationInfo.getId());
		return gClassificationCompare;
	}

	public static GClassificationCompare poToCompare(GClassification gClassification) {
		if (gClassification == null) {
			return null;
		}
		GClassificationCompare gClassificationCompare = new GClassificationCompare();
		gClassificationCompare.setParentId(gClassification.getParentId());
		gClassificationCompare.setType(gClassification.getType());
		gClassificationCompare.setSort(gClassification.getSort());
		gClassificationCompare.setName(gClassification.getName());
		gClassificationCompare.setTreeNodeId(gClassification.getTreeNodeId());
		gClassificationCompare.setParentTreeNodeId(gClassification.getParentTreeNodeId());
		gClassificationCompare.setId(gClassification.getId());
		return gClassificationCompare;
	}

	public static GClassification compareToPo(GClassificationCompare gClassificationCompare) {
		if (gClassificationCompare == null) {
			return null;
		}
		GClassification gClassification = new GClassification();
		gClassification.setParentId(gClassificationCompare.getParentId());
		gClassification.setType(gClassificationCompare.getType());
		gClassification.setSort(gClassificationCompare.getSort());
		gClassification.setName(gClassificationCompare.getName());
		gClassification.setTreeNodeId(gClassificationCompare.getTreeNodeId());
		gClassification.setParentTreeNodeId(gClassificationCompare.getParentTreeNodeId());
		gClassification.setId(gClassificationCompare.getId());
		return gClassification;
	}

	public static GClassificationInputId poToInputIdPo(GClassification gClassification) {
		if (gClassification == null) {
			return null;
		}
		GClassificationInputId gClassificationInputId = new GClassificationInputId();
		gClassificationInputId.setParentId(gClassification.getParentId());
		gClassificationInputId.setType(gClassification.getType());
		gClassificationInputId.setSort(gClassification.getSort());
		gClassificationInputId.setName(gClassification.getName());
		gClassificationInputId.setTreeNodeId(gClassification.getTreeNodeId());
		gClassificationInputId.setParentTreeNodeId(gClassification.getParentTreeNodeId());
		gClassificationInputId.setId(gClassification.getId());
		gClassificationInputId.setOperator(gClassification.getOperator());
		gClassificationInputId.setCreateTime(gClassification.getCreateTime());
		gClassificationInputId.setUpdateTime(gClassification.getUpdateTime());
		return gClassificationInputId;
	}

}
